package controller;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComponent;

import view.CreateEvent;
import view.ModifyEvent;

public class ActionModifyEvent implements ActionListener{

	boolean flag=true;

	@Override
	public void actionPerformed(ActionEvent e) {
		String name = ((JComponent) e.getSource()).getName();
		boolean flag = true;
		switch (name){
		case "contatto":{
			JButton j = new JButton();
			Color colore = j.getBackground();
			if (((JComponent) e.getSource()).getBackground()!=Color.green){
				((JComponent) e.getSource()).setBackground(Color.green);
				ModifyEvent.invitato.add(Integer.valueOf(((JComponent) e.getSource()).getComponent(0).getName()));
			}
			else
			{
				for (int i=0;i<ModifyEvent.invitato.size();i++){
					System.out.println(ModifyEvent.invitato.get(i));
					if (Integer.valueOf(((JComponent) e.getSource()).getComponent(0).getName())==ModifyEvent.invitato.get(i)){
						ModifyEvent.invitato.remove(i);
						break;
					}
				}
				((JComponent) e.getSource()).setBackground(colore);
			}

			flag=false;
		}break;
		case "typeChange":{
			CreateEvent.setPhoto((String) ModifyEvent.type.getSelectedItem());
		}break;
		case "next":{
			ModifyEvent.confirmEventProp(true);
			int id = ModifyEvent.Evento.getEvn_id();
			Engine.validateModifyEvent(id);
			flag=false;
		}break;
		case "annulla":{
			Engine.restartHome("ModifyEvent");
			flag=false;
		}break;
		case "upH":{
			if (ModifyEvent.posH<23)
				ModifyEvent.posH++;
			else
				ModifyEvent.posH = 0;
		}break;
		case "downH":{
			if (ModifyEvent.posH>0)
				ModifyEvent.posH--;
			else
				ModifyEvent.posH = 23;
		}break;
		case "upM":{
			if (ModifyEvent.posM<55)
				ModifyEvent.posM += 5;
			else
				ModifyEvent.posM = 0;
		}break;
		case "downM":{
			if (ModifyEvent.posM>0)
				ModifyEvent.posM -= 5;
			else
				ModifyEvent.posM = 55;
		}break;
		}
		if (flag){
			ModifyEvent.confirmEventProp(false);
			ModifyEvent.Uppdater();
			ModifyEvent.confirmEventProp(false);
		} else
			ModifyEvent.confirmEventProp(false);
		((JComponent)e.getSource()).requestFocus();
	}
}

